
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Tomcat 有哪几种Connector - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Tomcat 有哪几种Connector - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Tomcat中的Connector组件主要负责执行哪些核心任务？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Connector主要完成四项工作：1. 监听和接受连接，等待并建立与客户端的网络连接；2. 解析和处理协议，例如解析HTTP请求头和请求体；3. 转发请求到Servlet容器，由相应的Servlet处理；4. 传递响应到客户端，将Servlet生成的响应数据返回给客户端。</div>
          </div>
          <div class="card-source">来源: Connector是干什么的</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">描述一下Tomcat中BIO (Blocking I/O) Connector的工作模式及其主要缺点。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">BIO模式的Connector为每个客户端连接创建一个新的线程来处理。这种模型的优点是实现简单，易于理解和调试。然而，其主要缺点是线程的创建和销毁是昂贵的操作，因此在高并发场景下，性能和扩展性都较差。</div>
          </div>
          <div class="card-source">来源: BIO(Blocking I/O)模式</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">相较于BIO模式，NIO (Non-blocking I/O) Connector在处理连接方面有何根本不同？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">NIO Connector使用Java的NIO库实现非阻塞式I/O。它通过一个Selector轮询多个Channel，从而能在单个线程中处理多个连接。它采用事件驱动方式，使用有限的线程池处理所有连接，避免了为每个连接创建新线程的开销，从而提高了并发处理能力和资源利用率。</div>
          </div>
          <div class="card-source">来源: NIO(Non-blocking I/O)模式</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">什么是AJP Connector？它的主要用途是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">AJP Connector是一种用于Tomcat与前端Web服务器（如Apache HTTP服务器）之间通信的连接器。它的主要用途是优化Tomcat与前端Web服务器之间的通信，以提高生产环境中的性能、可靠性和通信效率。</div>
          </div>
          <div class="card-source">来源: BIO(Blocking I/O)模式</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">APR (Apache Portable Runtime) Connector是如何实现高性能的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">APR Connector通过Java Native Interface (JNI) 调用APR（一个跨平台的本地库）中的函数，从而实现对底层操作系统的直接访问。这使得它能够更好地利用操作系统提供的高级特性，如异步I/O和零拷贝，进而显著提高I/O操作的性能和效率。</div>
          </div>
          <div class="card-source">来源: APR(Apache Portable Runtime)模式</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Tomcat从哪个版本开始原生支持WebSocket？哪些类型的Connector支持WebSocket协议？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Tomcat从7.0.47版本以及8.0版本之后开始原生支持WebSocket协议。支持WebSocket的Connector主要有三种：NIO Connector、NIO2 Connector（Tomcat 8及以上版本引入）和APR Connector。</div>
          </div>
          <div class="card-source">来源: WebSocket支持</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">如何在Tomcat的server.xml文件中将Connector的协议模式配置为APR模式？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">要将Connector配置为APR模式，需要编辑server.xml文件，在<Connector>标签中将protocol属性设置为 "org.apache.coyote.http11.Http11AprProtocol"。示例配置为：<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol" />。</div>
          </div>
          <div class="card-source">来源: APR(Apache Portable Runtime)模式</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">在什么情况下应该优先选择使用NIO或NIO2 Connector？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当应用需要处理大量并发连接，并且对响应速度有较高要求时，应优先选择NIO或NIO2 Connector。例如实时通讯、在线游戏等高并发、高吞吐量的场景。如果你使用的是Tomcat 8及以上版本，NIO2 Connector能提供更好的性能和可扩展性。</div>
          </div>
          <div class="card-source">来源: 适用场景和选择</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">为什么在现代高负载的生产环境中通常不推荐使用BIO Connector？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为BIO Connector是传统的阻塞式I/O连接器，其性能较低且不支持高并发。每个连接占用一个线程的模式在高负载下会迅速耗尽服务器资源，导致性能瓶颈。因此，它不适用于需要处理大量并发请求的生产环境。</div>
          </div>
          <div class="card-source">来源: 适用场景和选择</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
